<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge" />
  <title>个人大事件-后台登录页</title>
  <link rel="stylesheet" type="text/css" href="css/reset.css" />
  <link rel="stylesheet" type="text/css" href="css/iconfont.css" />
  <link rel="stylesheet" type="text/css" href="css/main.css" />
  <!-- 引入bootstrap的css文件 -->
  <link rel="stylesheet" href="./libs/bootstrap/css/bootstrap.min.css" />
  <!-- 引入jq文件 -->
  <script src="./libs/jquery-1.12.4.min.js"></script>
  <!-- 引入bootstrap的js文件 -->
  <script src="./libs/bootstrap/js/bootstrap.min.js"></script>
  <script src="./js/http.js"></script>
</head>

<body>
  <div class="main_wrap">
    <div class="header">
      <a href="#" class="logo"><img src="images/logo.png" alt="" /></a>
      <div class="copyright">
        CopyRight © 2019 深圳百秀信息技术股份有限公司<br />All Rights Reserved
      </div>
    </div>

    <div class="login_form_con">
      <div class="login_title"></div>
      <form class="login_form">
        <i class="iconfont icon-user"></i>
        <i class="iconfont icon-key"></i>
        <input type="text" class="input_txt" placeholder="邮箱/手机号" value="阿泉" />
        <input type="password" class="input_pass" placeholder="密码" value="12345678" />
        <input type="submit" class="input_sub" value="登 录" />
      </form>
    </div>
  </div>
  <!-- bootstrap模态框 -->
  <!-- 注意:添加id名myModal -->
  <div class="modal fade" tabindex="-1" role="dialog" id="myModal">
    <div class="modal-dialog" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
              aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">温馨提示</h4>
        </div>
        <div class="modal-body">
          <p>One fine body&hellip;</p>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-default" data-dismiss="modal">确定</button>

        </div>
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->

</body>
<script>
  //入口函数
  $(function () {
    //一.登录
    //给登录按钮设置点击事件
    $('.input_sub').on('click', function (e) {
      //阻止submit默认提交
      e.preventDefault();
      //获取用户名和密码
      let username = $('.input_txt').val().trim();
      let password = $('.input_pass').val().trim();
      //非空判断
      if (username == '' || password == '') {
        $('.modal-body p').text('用户名或密码不能为空');
        // modal()可传参
        $('#myModal').modal({
          keyboard: false
        });
        // alert('用户名或密码错误')
      }
      //发出ajax请求
      $.ajax({
        type: 'post',
        //地址统一管理 封装地址在沙盒http.js中中 引入此js
        url: BigNew.user_login,
        data: {
          username: username,
          password: password,
        },
        success: function (backData) {
          $('.modal-body p').text(backData.msg);
          $('#myModal').modal({
            keyboard: false
          });
          // 注意: 因下行的代码是地址跳转 当执行到modal() 马上执行下行的地址跳转代码 
          //导致查看不到弹出的窗口 
          //所以要使用on('hidden.bs.modal)事件,在隐藏后再触发跳转
          $('#myModal').on('hidden.bs.modal', function (e) {
            if (backData.code == 200) {
              //保存令牌
              localStorage.setItem('userToken', backData.token)
              // 成功后跳转到主页
              window.location.href = 'index.html';
            }
          })

        }

      })

    })


  })
</script>

</html>